package dse;

import java.util.Collection;
import java.util.Vector;

/**
 * This probably isn't used anywhere now.  It is a network without clusters.  
 * 
 * @author Sam
 *
 */
public class GeneralNetwork extends Network {
	/** 
	 * This is all nodes in the network.  It should generally stay sorted by 
	 * id.
	 */ 
	private Vector<Node> nodes; 
	
	
	/**
	 * Find the node with the passed id, or null if it does not exist in the
	 * network.
	 * 
	 * @param id
	 * @return
	 */
	public Node lookupNode (int id) {
		return findN(0,nodes.size()/2,nodes.size()-1,id);
	}
	/**
	 * Go through all nodes in the network.
	 * @return
	 */
	public Collection<Node> nodes () {
		return nodes;
	}
	/**
	 * Returns the number of nodes in the network.
	 * @return
	 */
	public int nodeCount () {
		return nodes.size();
	}
	/**
	 * Gets the maximum id of all nodes in the network.  This is useful for 
	 * hashing.
	 * @return
	 */
	public int maxNodeId () {
		return nodes.size();
	}
	/**
	 * Finds and returns the cluster with the given id.
	 * 
	 * @param id
	 * @return
	 */
	public Cluster lookupCluster (int id) {
		return null;
	}
	/**
	 * Go through all clusters in the network.
	 * @return
	 */
	public Iterable<Cluster> clusters () {
		return (new Vector<Cluster>());
	}
	/**
	 * Whether or not the network has clusters.
	 * @return
	 */
	public boolean hasClusters () {		
		return false;
	}
	/**
	 * Returns the number of clusters in the network.
	 * @return
	 */
	public int clusterCount () {
		return 0;
	}
	/**
	 * Gets the maximum id of all clusters in the network.  This is useful for 
	 * hashing.
	 * @return
	 */
	public int maxClusterId () {
		return 0;
	}
	
	/**
	 * This basically does a binary search on nodes.
	 */
	private Node findN (int smin, int sat, int smax, int id) {
		Node n = nodes.elementAt(sat);
		int rel = n.compareTo(id);
		if (rel == 0)
			return n;
		
		if (rel < 0)
			// go higher
			smin = smin + 1;
		else
			// else go lower
			smax = smax - 1;
		if (smin > smax)
			return null;
		return findN (smin, (smax+smin)/2, smax, id);
	}
}
